<cfcomponent name="packer">
	<cfset path = GetDirectoryFromPath(GetCurrentTemplatePath()) & "js">
	<cffile action="read" file="#path#\words.js" variable="words">
	<cffile action="read" file="#path#\base2.js" variable="base2">
	<cffile action="read" file="#path#\packer.js" variable="pack">

	<cffunction access="public" output="false" name="pack" returntype="String">
		<cfargument name="script" required="true" default="" type="string">
		<cfargument name="type" required="false" default="script" type="string">
		<cfargument name="encode" required="false" default="true" type="boolean">
		<cfargument name="shrink" required="false" default="true" type="boolean">
		
		<cfif NOT Len(script)>
			<cfreturn "You must include a script or file name">
		<cfelseif type is "file">
			<cffile action="read" file="#script#" variable="script">
		</cfif>
		
		<cfscript>
		    rhinoObj = createObject("java","org.mozilla.javascript.Context").init();
		    cx = rhinoObj.enter();
			scope = cx.initStandardObjects();
				scope.put("script",scope,javacast("string",script));
				scope.put("base62",scope,javacast("boolean",encode));
				scope.put("shrink",scope,javacast("boolean",shrink));
			packer =  base2 & pack & words;
			go = "var packer = new Packer; packer.pack(script, base62, shrink);""
				cx.evaluateString(scope,javacast("string",packer),javacast("string","<cmd>"), 1, javacast("null","") );
			packed = cx.evaluateString(scope,javacast("string",go),javacast("string","<cmd>"), 1, javacast("null","") );
		    cx.exit();
		</cfscript>
		
		<cfreturn packed>
	</cffunction>
</cfcomponent>